#pragma once

#ifndef __SOCKET_H_INCLUDED
#define __SOCKET_H_INCLUDED

#include <winsock.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

/*
 * Number of colors initialized in WinsockStart
 */
#define COLORCOUNT		3
#define WM_SOCKET_ASYNC		WM_USER + 100

#define BROADCAST_PORT 5021
#define CONNECT_PORT 5022

class Commu
{
public:
	struct socketType
	{
		string Name;
		string IP;
		int PlayerNum;
		int EnterUsers;	
	};
	std::vector<socketType> ServerInfos;
	SOCKET severSocket;
	SOCKET userScoket;
	
public:
	Commu();
	~Commu();
	bool WinsockFSL();
	bool WinsockSeedBroad(const char *info);	
	bool SendMsgSever(const char *Msg,int len,char *host, short port, SOCKET s);
	socketType WinsockRecBroad();
	bool connectSockter(const char* ip, unsigned short port);

	bool ClienHandleBroad(socketType msg);
	void ServerHandleBroad(socketType msg);
	socketType messageDistinctive(char* buffMess, const  char* ip);

	void WinsockError(int nSocketError, const char *szFunction);
	
private:	
	bool falgeSever;	
};

#endif